{%include file="header.html"%}
<style>
table{text-align: center;}
th a{ color:#000000;}
#aspnetForm2{margin-left:11.5px;margin-bottom: 30px;}
.submit{
  width:70px;vertical-align: middle;padding:2px 0px;
}
.sx{width:100px;}
.goods_jy{
  disabled:;
}
.action{
  display:none;
}
</style>
<body>
<div class="fixed-bar">
  <div class="item-title">
    <h3>商品列表</h3>
    <form action="goods.php" name="searchForm" method="get">
        <input type="hidden" name="act" value="list">
        <!-- 分类 -->
        <select name="cat_id"><option value="0">所有分类</option>{%$cat_list%}</select>
        <!-- 品牌 -->
        <select name="brand_id">
        <option value="0">所有品牌</option>
        {%foreach from=$brand_list key=key item=brands%}
        <option value="{%$key%}" {%if $sou.brand_id == $key%} selected="selected" {%/if%}>
        {%$brands%}
        </option>
        {%/foreach%}
        </select>
        <!-- 推荐 -->
        <select name="is_best"><option value="0">全部</option>{%foreach from=$ranks_list item=ranks%}<option {%if $sou.is_best == $ranks.id%} selected="selected" {%/if%} value="{%$ranks.id%}">{%$ranks.name%}</option>{%/foreach%}</select>
        <!-- 店铺 -->
        <select name="shop_name"><option value="0">店铺</option>{%foreach from=$shops_list item=shops%}<option {%if $sou.shop_name == $shops.s_id%} selected="selected" {%/if%} value="{%$shops.s_id%}">{%$shops.shop_name%}</option>{%/foreach%}</select>
        <!--上架-->
        <select name="is_on_sale"><option {%if $sou.is_on_sale == 2%} selected="selected" {%/if%} value="2">状态</option>
        <option {%if $sou.is_on_sale == 1%} selected="selected" {%/if%} value="1">上架</option>
        <option {%if $sou.is_on_sale == 0%} selected="selected" {%/if%} value="0">下架</option>
        </select>
        <!--关键字-->
        <input type="text"  style="width:180px; height:18px;margin-left:5px; vertical-align: middle;" name="keywords" value="{%if $sou.keywords%} {%$sou.keywords%} {%/if%}" placeholder="关键字">
        <input value=" 搜索 " id="but_sousuo" style="width:50px; height:27px; margin-top:13px;" class="button" type="submit">
        <div style="background:rgba(251,112,45,1);width:125px;height:40px;float:right;text-align:center;border-radius:5px;">
          <a href="goods.php?act=add">
            <h5 style="padding:10px;color:#fff;">添加商品</h5>
          </a>
        </div>
    </form>
  </div>
</div>
<div class="fixed_bottom">
  <form method="post" action="goods.php?act=batch_manage" id="aspnetForm" name="form1">
    <table align="center;" class="table tb-type2">
      <thead>
        <tr>
          <th width="50"><input style="vertical-align: inherit;" id="quan" type="checkbox">&nbsp;<a>编号</a></th>
          <th width="25%"><a>商品名称</a></th>
          <th><a>商品展示</a></th>
          <th><a>价格</a></th>
          <th><a>库存</a></th>
          <th><a>上架</a></th>
          <th><a>排序</a></th>
          <th><a>审核</a></th>
          <th><a>操作</a></th>
        </tr>
      </thead>
      <tbody id="sortable">
        {%foreach from=$goods_info item=list key=k%}
            <tr>
              <td><input style="vertical-align: inherit;" name="idx[]" type="checkbox" value="{%$list.goods_id%}">&nbsp;{%$list.goods_id%}</td>
              <td>{%$list.goods_name%}</td>
              <td><img height="50" src="../{%$list.goods_thumb%}"/></td>
              <td>￥{%$list.shop_price%}</td>
              <td>{%$list.goods_number%}</td>
              <td><i style="cursor:pointer;" onclick="ajax_sale(this,{%$list.goods_id%},{%$list.is_on_sale%})" class="fa {%if $list.is_on_sale==1%}fa-check{%else%}fa-close{%/if%}"></i></td>
              <td>{%$list.sort_order%}</td>
              <td></td>
              <td>
                <a href="goods.php?act=add&goods_id={%$list.goods_id%}">编辑</a>
                <a href="goods.php?act=del_goods&goods_id={%$list.goods_id%}">删除</a>
                {%if $list.goods_products%}
                <a title="货品库存详情" href="goods.php?act=products_list&goods_id={%$list.goods_id%}">货品</a>
                {%/if%}
              </td>
            </tr>
        {%/foreach%}
        <input type="hidden" id="ids_list" />
      </tbody>
    </table>
    <div class="page">{%$page%}</div>
    <div id="aspnetForm2">
      <select style="width:150px;" name="type" id="sx" required>
            <option value=''>请选择...</option>
            <option value='1'>回收站</option>  
            <option value='2'>上架</option>
            <option value='3'>下架</option>
            <option value='4'>转移到分类</option>  
      </select>&nbsp;&nbsp;
      <select class="action" name="catId" id="type"><option value="">所有分类</option>{%$cat_list%}</select>&nbsp;&nbsp;
      <input class="submit" disabled type="submit" value="确定">
    </div>
  </form>
</div>
</body>
<script>
//修改确定按钮状态
$("input[type=checkbox]").click(function(){
    if($("input[type=checkbox]").is(':checked')){
        $(".submit").attr("disabled",false);
    }else{
        $(".submit").attr("disabled",true);
        $("#quan").attr('checked',false);
    }
});
//批量操作
$("#sx").click(function(){
    var val=$(this).val();
    if(val==4){
      $("#type").removeClass("action");
      $("#type").attr("required","required");
    }else{
      $("#type").addClass("action");
      $("#type").removeAttr("required");
    }
});
//全选全不选
var i=0;
$("#quan").click(function(){
  $(this).attr('aa',i);
  idx=$(this).attr('aa');
  if(idx%2==0){
      $("input[type=checkbox]").attr('checked',true); 
  }else{
      $("input[type=checkbox]").attr('checked',false);
      $(".submit").attr("disabled",true);
  }
  i++;
});
//ajax改变是否状态
function ajax_sale(obj,id,price){
  if(price==1){
    prices="1";
  }else{
    prices="2";
  }
  $.post("goods.php",{act:'ajax_sale',goods_id:id,zt:prices},function(data){
      if(data==1){
      layer.msg("操作成功！");
      if(prices==1){
        $(obj).attr("onclick","ajax_sale(this,"+id+",2)");
        $(obj).removeClass("fa-check");
        $(obj).addClass("fa-close");
      }else if(prices==2){
        $(obj).attr("onclick","ajax_sale(this,"+id+",1)");
        $(obj).removeClass("fa-close");
        $(obj).addClass("fa-check");
      }
    }else if(data==2){
      layer.msg("操作失败！");
    }
  });  
}
</script>
</html>